import {type MockMethod, Recordable, RespThisType} from "vite-plugin-mock";
import {
    loadAssetOfHolderPageUrl,
    loadHolderForAssetPageUrl, removeAssetOfHolderUrl,
    saveAssetOfHolderUrl,
    saveHolderForAssetUrl
} from "../src/apis/url";
import {SERVERS} from "../src/stores/conf";

const PREFIX: string = 'mock';

const mock: Array<MockMethod> = [
    {
        url: saveAssetOfHolderUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
                data: {}
            }
        }
    },
    {
        url: saveHolderForAssetUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
                data: {}
            }
        }
    },
    {
        url: removeAssetOfHolderUrl('/mock'),
        method: 'post',
        response: () => {
            return {
                code: 0,
                message: "操作成功",
                data: {}
            }
        }
    },
    {
        url: loadAssetOfHolderPageUrl('/mock'),
        method: 'post',
        response: (opt: {
            url: Recordable;
            body: Recordable;
            query: Recordable;
            headers: Recordable;
        }) => {
            let total: number = 0;
            const data: any = [];

            if ('USER' === opt.body.holdType) {
                if ('1' === opt.body.holdId) {
                    if ('PERMIT' === opt.body.assetType) {
                        total = 2;
                        data.push({
                            id: '1',
                            name: '删除用户',
                            code: 'user:del'
                        });
                        data.push({
                            id: '2',
                            name: '增加用户',
                            code: 'user:add'
                        });
                    } else if ('ROLE' === opt.body.assetType) {
                        total = 1;
                        data.push({
                            id: '1',
                            name: '工程师',
                            code: 'eng',
                            path: '/1'
                        });
                    }
                } else if ('2' === opt.body.holdId) {
                    if ('PERMIT' === opt.body.assetType) {
                        total = 1;
                        data.push({
                            id: '2',
                            name: '增加用户',
                            code: 'user:add'
                        });
                    }
                }
            } else if ('ROLE' === opt.body.holdType) {
                if ('1' === opt.body.holdId) {
                    if ('PERMIT' === opt.body.assetType) {
                        total = 2;
                        data.push({
                            id: '1',
                            name: '删除用户',
                            code: 'user:del'
                        });
                        data.push({
                            id: '2',
                            name: '增加用户',
                            code: 'user:add'
                        });
                    } else if ('MENU' === opt.body.assetType) {
                        total = 2;
                        data.push({
                            id: '1',
                            name: '首页',
                        });
                        data.push({
                            id: '2',
                            name: '资源管理',
                        });
                    }
                }
            } else if ('GROUP' === opt.body.holdType) {
                if ('1' === opt.body.holdId) {
                    if ('PERMIT' === opt.body.assetType) {
                        total = 2;
                        data.push({
                            id: '1',
                            name: '删除用户',
                            code: 'user:del'
                        });
                        data.push({
                            id: '2',
                            name: '增加用户',
                            code: 'user:add'
                        });
                    } else if ('MENU' === opt.body.assetType) {
                        total = 2;
                        data.push({
                            id: '1',
                            name: '首页',
                        });
                        data.push({
                            id: '2-1',
                            name: '客户管理',
                        });
                    } else if ('ROLE' === opt.body.assetType) {
                        total = 1;
                        data.push({
                            id: '1',
                            name: '工程师',
                            code: 'eng',
                            createTime: '2024-01-02 12:00'
                        });
                    }
                }
            } else if ('CLIENT' === opt.body.holdType) {
                if ('1' === opt.body.holdId) {
                    if ('PERMIT' === opt.body.assetType) {
                        total = 2;
                        data.push({
                            id: '1',
                            name: '删除用户',
                            code: 'user:del'
                        });
                        data.push({
                            id: '2',
                            name: '增加用户',
                            code: 'user:add'
                        });
                    } else if ('ROLE' === opt.body.assetType) {
                        total = 2;
                        data.push({
                            id: '1',
                            name: '总部',
                            code: 'all',
                            path: '/1'
                        });
                        data.push({
                            id: '1-1',
                            name: '总经理',
                            code: 'eng',
                            path: '/1/1-1'
                        });
                    } else if ('MENU' === opt.body.assetType) {
                        total = 2;
                        data.push({
                            id: '1',
                            name: '首页',
                        });
                        data.push({
                            id: '2-1',
                            name: '客户管理',
                        });
                    } else if ('ROLE' === opt.body.assetType) {
                        total = 2;
                        data.push({
                            id: '1',
                            name: '管理员',
                        });
                        data.push({
                            id: '2',
                            name: '总部',
                        });
                    }
                }
            }
            return {
                code: 0,
                message: "操作成功1111",
                data: {
                    total: total,
                    data: data
                }
            }
        }
    },
    {
        url: loadHolderForAssetPageUrl('/mock'),
        method: 'post',
        response: (opt: {
            url: Recordable;
            body: Recordable;
            query: Recordable;
            headers: Recordable;
        }) => {
            let total: number = 0;
            const data: any = [];
            if (opt.body.server === SERVERS.REALM) {
                if ('USER' === opt.body.assetType) {
                    if ('GROUP' === opt.body.holdType) {
                        total = 2;
                        data.push({
                            id: '1',
                            name: '人事部',
                        });
                        data.push({
                            id: '2',
                            name: '市场部',
                        });
                    }
                }
            } else {
                if ('PERMIT' === opt.body.assetType) {
                    if ('1' === opt.body.assetId) {
                        if ('USER' === opt.body.holdType) {
                            total = 2;
                            data.push({
                                id: '1',
                                name: 'licode',
                            });
                            data.push({
                                id: '2',
                                name: 'wangrong',
                            });
                        } else if ('GROUP' === opt.body.holdType) {
                            total = 2;
                            data.push({
                                id: '1',
                                name: '人事部',
                            });
                            data.push({
                                id: '2',
                                name: '市场部',
                            });
                        } else if ('ROLE' === opt.body.holdType) {
                            total = 1;
                            data.push({
                                id: '1',
                                name: '工程师',
                                code: 'eng'
                            });
                        } else if ('CLIENT' === opt.body.holdType) {
                            total = 1;
                            data.push({
                                id: '1',
                                name: '小程序APP',
                            });
                        }
                    } else if ('2' === opt.body.assetId) {
                        if ('GROUP' === opt.body.holdType) {
                            total = 1;
                            data.push({
                                id: '2',
                                name: '市场部',
                            });
                        }
                    }
                } else if ('ROLE' === opt.body.assetType) {
                    if ('1' === opt.body.assetId) {
                        if ('USER' === opt.body.holdType) {
                            total = 2;
                            data.push({
                                id: '1',
                                name: 'licode',
                            });
                            data.push({
                                id: '2',
                                name: 'wangrong',
                            });
                        } else if ('GROUP' === opt.body.holdType) {
                            total = 2;
                            data.push({
                                id: '1',
                                name: '人事部',
                            });
                            data.push({
                                id: '2',
                                name: '市场部',
                            });
                        }
                    }
                } else if ('MENU' === opt.body.assetType) {
                    if ('1' === opt.body.assetId) {
                        if ('USER' === opt.body.holdType) {
                            total = 2;
                            data.push({
                                id: '1',
                                name: 'licode',
                            });
                            data.push({
                                id: '2',
                                name: 'wangrong',
                            });
                        } else if ('GROUP' === opt.body.holdType) {
                            total = 2;
                            data.push({
                                id: '1',
                                name: '人事部',
                            });
                            data.push({
                                id: '2',
                                name: '市场部',
                            });
                        }
                    }
                }
            }
            return {
                code: 0,
                message: "操作成功",
                data: {
                    total: total,
                    data: data
                }
            }
        }
    },
]

export default mock;
